/*
 *
 * @ProjectName:    my_umi_app
 * @Package:
 * @ClassName:      today_ad_details
 * @Description:    JSX文件
 * @Author:         SuPeiSen
 * @CreateDate:     2021/3/5 10:48 上午
 * @UpdateDate:     2021/3/5 10:48 上午
 * @UpdateRemark:   更新说明：
 * @Version:        1.0
 */

import ProTable, { ProColumns } from '@ant-design/pro-table';
import { AdItemType } from '@/type/ad_type';
import { AppImageUrl } from '@/config/app_config';
import { message, Switch, Tag } from 'antd';
import { history } from '@@/core/history';
import { numberToBool } from '@/utils/app_fun';
import { GetAdListApi, UpdateAdStatusByIdApi } from '@/service/ad_api';
import { DeleteShareUrlApi } from '@/service/share_url_api';
import { SortOrder } from 'antd/lib/table/interface';
import React from 'react';
import { updateCategoryApi } from '@/service/category_api';
import { AaStatisticsItemType } from '@/type/statistics_type';
import { GetAdStatisticsDetailsApi } from '@/service/statistics_api';
import { IRouteComponentProps } from 'umi';

const columns: ProColumns<AaStatisticsItemType>[] = [
  {
    title: 'id',
    dataIndex: 'id',
    key: 'id',
    search: false,
    editable: false,
  },
  {
    title: '点击次数',
    dataIndex: 'ad_click_num',
    render: (dom, item) => {
      return <Tag color="red">{item.ad_click_num}</Tag>;
    },
  },
  {
    title: '总数',
    dataIndex: 'today_num',
    render: (dom, item) => {
      return <Tag color="blue">{item.today_num}</Tag>;
    },
  },
  {
    title: '广告名称',
    dataIndex: 'ad_title',
    editable: false,
    render: (dom, item) => {
      return <i style={{ fontWeight: 'bold' }}>{item.ad_title}</i>;
    },
  },
  {
    title: '广告链接',
    dataIndex: 'url_path',
    editable: false,
    render: (dom, item) => {
      return (
        <i
          onClick={() => {
            window.open(item.ad_url);
          }}
          style={{ color: 'blue', textDecoration: 'underline' }}
        >
          {item.ad_url}
        </i>
      );
    },
  },
  {
    title: '邮箱',
    dataIndex: 'ad_email',
    editable: false,
    render: (dom, item) => {
      return <Tag>{item.ad_email}</Tag>;
    },
  },
  {
    title: '排序',
    dataIndex: 'px',
    editable: false,
    render: (dom, item) => {
      return <Tag>{item.px}</Tag>;
    },
  },
  {
    title: '添加时间',
    dataIndex: 'add_time',
  },
  {
    title: '备注',
    dataIndex: 'remarks',
  },
];

export default (props: IRouteComponentProps<{}, { id: string }>) => {
  const getAdStatisticsList = async (
    params: {
      pageSize?: number;
      current?: number;
      keyword?: string;
    },
    sort: {
      [key: string]: SortOrder;
    },
    filter: {
      [key: string]: React.ReactText[];
    },
  ) => {
    const model = await GetAdStatisticsDetailsApi({
      page: params.current ?? 1,
      limit: params.pageSize ?? 10,
      id: Number(props.location.query.id),
    });
    if (model.success) {
      return {
        success: true,
        data: model.data!.data.lists,
        total: model.data!.data.total,
      };
    }
    return {
      data: [],
      success: false,
    };
  };

  return (
    <ProTable<AaStatisticsItemType>
      columns={columns}
      rowKey="id"
      request={getAdStatisticsList}
      pagination={{ pageSize: 20 }}
    />
  );
};
